﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>APS排产查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData()">
    <!-- 报表标题 -->
    <vue2-report-header :title="'APS排产查询报表'"></vue2-report-header>
    <div style="padding: 10px;" id="queryZone">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        :disabled="formDisabled">
        <el-form-item label="组织结构:" prop="selectOrg">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:300px;" @change="selectOrgChange">
          </el-cascader>
        </el-form-item>

        <el-form-item label="工人:">
          <el-select v-model="queryInfo.workerid" placeholder="请选择" clearable filterable style="width: 100px;">
            <el-option v-for="i in workerList" :key="i.employeeid" :label="i.fullname" :value="i.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='resourcename' label="设备:">
          <el-autocomplete v-model.trim="queryInfo.resourcename" placeholder="请输入设备编号" :trigger-on-focus="false"
            :fetch-suggestions="getResourcenameAsync" :value-key="'resourcename'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="件号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入件号" :trigger-on-focus="false"
            :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500" style="width:300px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500" style="width:300px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="状态:">
          <el-select v-model="queryInfo.status" filterable clearable style="width:140px;">
            <el-option :key="'按时完成'" :label="'按时完成'" :value="'按时完成'"></el-option>
            <el-option :key="'超期完成'" :label="'超期完成'" :value="'超期完成'"></el-option>
            <el-option :key="'未完成'" :label="'未完成'" :value="'未完成'"></el-option>
            <el-option :key="'超期未完'" :label="'超期未完'" :value="'超期未完'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="下发状态:">
          <el-select v-model="queryInfo.apsPlanDetailStatus" filterable clearable style="width:140px;">
            <el-option :key="'未下发'" :label="'未下发'" :value="'未下发'"></el-option>
            <el-option :key="'下发'" :label="'下发'" :value="'下发'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工序所属分厂:">
          <el-select v-model="queryInfo.specfactoryid" placeholder="请选择" filterable clearable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="加工开始时间:" prop="starttime">
          <el-date-picker v-model="queryInfo.starttime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="加工结束时间:" prop="endtime">
          <el-date-picker v-model="queryInfo.endtime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="设备开始时间:" prop="resstarttime">
          <el-date-picker v-model="queryInfo.resstarttime" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="设备结束时间:" prop="resendtime">
          <el-date-picker v-model="queryInfo.resendtime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-popover placement="top-start" title="报表说明:" width="500" trigger="hover">
          <el-button icon="el-icon-info" slot="reference">报表说明</el-button>
          <p>1. 查询通过APS排产所产生的所有数据。</p>
          <p>2. 报表未做数据过滤、且为实时数据。</p>
        </el-popover>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData" :loading="loading">查询
          </el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="主制分厂" prop="factoryname" width="120" show-overflow-tooltip sortable></el-table-column>
        <el-table-column label="工序所属分厂" prop="specfactoryname" width="130" show-overflow-tooltip sortable>
        </el-table-column>
        <el-table-column label="人员" prop="fullname" width="80" show-overflow-tooltip sortable></el-table-column>
        <el-table-column label="设备编号" prop="resourcename" width="140" show-overflow-tooltip sortable></el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="120" show-overflow-tooltip sortable></el-table-column>
        <el-table-column label="流水卡号" prop="containername" width="180" show-overflow-tooltip sortable>
        </el-table-column>
        <el-table-column label="数量" prop="qty" width="80"></el-table-column>
        <el-table-column label="工序" prop="workflowstepname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="加工开始时间" prop="starttime" width="160" :formatter="replaceDate" sortable>
        </el-table-column>
        <el-table-column label="加工结束时间" prop="endtime" width="160" :formatter="replaceDate" sortable></el-table-column>
        <el-table-column label="设备开始时间" prop="resstarttime" width="160" :formatter="replaceDate"></el-table-column>
        <el-table-column label="设备结束时间" prop="resendtime" width="160" :formatter="replaceDate"></el-table-column>
        <el-table-column label=" 状态" prop="status" width="100" sortable>
          <template slot-scope="scope" v-if="scope.row.status">
            <el-tag v-if="scope.row.status === '按时完成'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '超期完成'" type="warning">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '超期未完'" type="danger">{{scope.row.status}}</el-tag>
            <el-tag v-else type="info">{{scope.row.status}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="工区" prop="workcentername" width="120" show-overflow-tooltip sortable></el-table-column>
        <el-table-column label="班组" prop="teamname" width="120" show-overflow-tooltip sortable></el-table-column>
        <el-table-column label="排产人" prop="planemp" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="工序不加工" prop="undospec" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="派工人" prop="dispatchemployeename" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="派工时间" prop="dispatchdate" width="160" :formatter="replaceDate"></el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[20,100,500]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getUserInfo, getWorkerList, getMESOrginazition } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { replaceDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js';
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        replaceDate,
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: {
          selectOrg: [],
          specfactoryid: '',//工序所属分厂
          workerid: '',
          resourcename: '',
          mfgordername: '',
          productname: '',
          containername: '',
          starttime: '',
          endtime: '',
          status: '',
          apsPlanDetailStatus: '',
          resstarttime: '',
          resendtime: '',
          currentPage: 1,//当前页
          pageSize: 20//每页显示条数
        },
        dataList: [],
        orginazition: [],
        factoryList: [],
        workerList: [],
        userInfo: {},
        formDisabled: false,
        rules: {
          selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }],
          starttime: [{ required: true, message: '加工开始时间不能为空', trigger: 'change' }]
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        // 查询设备
        getResourcenameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getResourcenameAsync', name: 'resourcename', value, callback });
        },
        async selectOrgChange(val) {
          this.queryInfo.workerid = null;
          if (val) {
            const [factoryid, workcenterid, teamid] = val;
            this.workerList = await getWorkerList({ factoryid, workcenterid, teamid });
          }
        },
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/APSPlanReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        // 导出
        async getExportExcel() {
          const config = {
            url: '../handler/report/APSPlanReport.ashx?action=getExportExcel',
            data: { type: 'getExportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const today = dayjs().format('YYYY-MM-DD');
        this.queryInfo.starttime = [today, today];
        this.orginazition = await getMESOrginazition({ factoryCode: '600|601|602|604|607|608|609' });
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        if (!this.userInfo) { this.formDisabled = true; return; }
        const { factoryid, workcenterid, teamid, auth, employeeid, employeename, fullname } = this.userInfo;
        for (const i of this.orginazition) {
          this.factoryList.push({ factoryid: i.value, factoryname: i.label });
        }
        if (auth === '工人') {
          this.queryInfo.selectOrg = [factoryid, workcenterid, teamid];
          this.workerList.push({ employeeid, employeename, fullname });
          this.queryInfo.workerid = employeeid;
        }
        if (auth === '班组长') {
          this.queryInfo.selectOrg = [factoryid, workcenterid, teamid];
          this.workerList = await getWorkerList({ factoryid, workcenterid, teamid });
        }
        if (auth === '工区长') {
          this.queryInfo.selectOrg = [factoryid, workcenterid];
          this.workerList = await getWorkerList({ factoryid, workcenterid });
        }
        if (auth === '管理员' && factoryid !== null) {
          this.queryInfo.selectOrg = [factoryid];
          this.workerList = await getWorkerList({ factoryid })
        }
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>